package com.pmsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.Room;
import com.pmsystem.pojo.RoomShow;
import com.pmsystem.service.RoomService;

/**
 * 
* <p>Title: RoomController</p>  
* <p>Description:处理房间信息的控制器 </p>  
* @author 树昌  
* @date 2019年1月22日
 */
@Controller
@RequestMapping("Information/")
public class RoomController {

	@Autowired
	RoomService roomService;
	
	
	/**
	 * 
	 * <p>Title: addBuilding</p>  
	 * <p>Description:添加一条房间的记录 </p>  
	 * @author 树昌
	 * @param room
	 * @return
	 */
	@RequestMapping(value="addroom",method=RequestMethod.POST)
	public String addRoom(Room room) {
		
		if(room.getBlgBuildingId()!=null) {		
			roomService.addRoom(room);
			return "Information/success";
		}else {
			return "error";
		}
	}
	
	/**
	 * 
	 * <p>Title: showRoom</p>  
	 * <p>Description:显示所有的房间记录的控制器 </p>  
	 * @author 树昌
	 * @return 不做跳转
	 */
	@RequestMapping(value="showroom",method=RequestMethod.POST)
	@ResponseBody
	public List<RoomShow> showRoom(String keyword,Integer startRow,Integer pageSize,Integer RID) {
		System.out.println(keyword+"--"+startRow+"--"+pageSize);
		return roomService.showRoom(keyword, startRow, pageSize,RID);
	}
	
	
	/**
	 * 
	 * <p>Title: deleteRoom</p>  
	 * <p>Description:删除一条房间的记录 </p>  
	 * @author 树昌
	 * @param room
	 * 不做跳转
	 */
	@RequestMapping(value="deleteroom",method=RequestMethod.POST)
	@ResponseBody
	public void deleteRoom(Room room) {
		roomService.deleteRoom(room);
	}
	
	
	/**
	 * 
	 * <p>Title: updateRoom</p>  
	 * <p>Description:根据房间ID修改一条房间的信息 </p>  
	 * @author 树昌
	 * @param room
	 * @return 跳转到查询所有房间信息的页面
	 */
	@RequestMapping(value="updateroom",method=RequestMethod.POST)
	public String updateRoom(Room room) {
		boolean row = roomService.updateRoom(room);
		if(row) {
			return "Information/showroom";
		}else {
			return "error";
		}
	}
}
